<script type="text/javascript">
    function functionNewItem(param) {
        window.location.href = param;
    }

    function functionSearchs(param) {
        document.searchForm.action = param;
        document.searchForm.submit();
    }

    function functionResets(param) {
        window.location.href = param;
    }

    function functionDeleteItem(param, paramPembeda) {
        var arrayText = "";
        var checkBox = document.getElementsByName("check");
        var hiddenId = document.getElementsByName("hiddenId");
        var countFalse = 0;
        for (var i = 0; i < checkBox.length; i++) {
            if (checkBox[i].checked === true) {
                if (i === 0) {
                    arrayText = arrayText + hiddenId[i].value;
                } else {
                    arrayText = arrayText + "," + hiddenId[i].value;
                }
            } else if (checkBox[i].checked === false) {
                countFalse++;
            }
        }
        if (checkBox.length === countFalse) {
            alert("Tidak ada data yang di"+paramPembeda+"!");
        } else {
            var kata = "";
            if (paramPembeda === "delete") {
                kata = "delete";
            } else if (paramPembeda === "submit") {
                kata = "submit";
            }
            var confirmValue = confirm("Yakin akan di "+kata+"?");
            if (confirmValue === true) {
                window.location.href = param + "?idArray=" + arrayText;
            } else {
                return;
            }
        }
    }

    function functionClickAll() {
        var checked = false;
        if (document.getElementById("checkMaster").checked === true)
            checked = true;

        var tbl = document.getElementById("lineItemTable");
        var rowLen = tbl.rows.length;
        for (var idx = 1; idx < rowLen; idx++) {
            var row = tbl.rows[idx];
            var cell = row.cells[0];
            var node = cell.lastChild;
            node.checked = checked;
        }
    }
    
    function functionDeleteItemList(param) {
        var arrayText = "";
        var checkBox = document.getElementsByName("check");
        var hiddenId = document.getElementsByName("hiddenId");
        
        var countFalse = 0;
        
        for (var i = 0; i < checkBox.length; i++) {
            if (checkBox[i].checked === true) {
                if (i === 0) {
                    arrayText = arrayText + hiddenId[i].value;
                } else {
                    arrayText = arrayText + "," + hiddenId[i].value;
                }
            } else if (checkBox[i].checked === false) {
                countFalse++;
            }
        }
        if (checkBox.length === countFalse) {
            alert("Tidak ada data yang dihapus!");
        } else {
            window.location.href = param + "?idArray=" + arrayText;
        }
    }
</script>
